<template>
  <div class="hy-tree">
    <div class="layer-title">
      <div class="title">设备图层</div>
      <el-icon class="close-icon" @click="atlasChange('layer')">
        <Close />
      </el-icon>
    </div>
    <el-scrollbar max-height="600px">
      <div class="tree-box">
        <el-tree
          :props="defaultProps"
          :data="treeData"
          :show-checkbox="true"
          ref="treeRef"
          node-key="id"
          default-expand-all
          @check-change="handleNodeClick"
        >
          <template #default="{ node, data }">
            <el-tooltip :content="getNodeLabel(node, data)" placement="right" :show-after="500" effect="dark">
              <span class="custom-tree-node">{{ getNodeLabel(node, data) }}</span>
            </el-tooltip>
          </template>
        </el-tree>
      </div>
    </el-scrollbar>
  </div>
</template>

<script setup lang="ts">
import { useAtlasStore } from '@/store/modules/atlas';
import { onMounted } from 'vue';

const atlasStore = useAtlasStore();
const { atlasChange, handleNodeClick, getList } = atlasStore;
const { treeData, treeRef } = storeToRefs(atlasStore);
const defaultProps = {
  children: 'child',
  label: 'name'
};

const getNodeLabel = (node: any, data: any) => {
  return node.label + (data.total !== undefined && data.total !== null ? `(${data.total})` : '');
};

onMounted(() => {
  getList();
});
</script>

<style lang="scss">
.hy-tree {
  padding: 20px;
  box-sizing: border-box;
  z-index: 99;
  color: #fff;
  background-color: rgba($color: #004068, $alpha: 0.6);
  width: 25rem;
  border: 2px solid #045bbd;
  box-shadow: inset 0 0 25px 0 #1b5bfb;

  .layer-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    margin-bottom: 10px;

    .title {
      font-family: PangMenZhengDao;
      font-size: 1.125rem;
    }

    .close-icon {
      cursor: pointer;
    }

    .title:before {
      content: '';
      display: inline-block;
      width: 0.375rem;
      height: 1rem;
      margin-right: 0.25rem;
      background-color: #3ba0ff;
      vertical-align: text-top;
    }
  }

  .el-tree {
    width: 100%;
    background-color: transparent;
    color: #fff;
    font-size: 16px;
  }

  .el-tree__empty-text {
    font-size: 16px;
    color: #00f5ff;
  }

  .el-tree-node__expand-icon {
    color: #00ffff;
    font-size: 16px;
  }

  .el-tree-node__expand-icon.is-leaf {
    color: transparent;
    cursor: default;
  }

  .el-checkbox__inner {
    border-radius: 0 0 0 0;
    opacity: 1;
    background: transparent;
    border: 1px solid #00ffff;
  }

  .el-tree-node > .el-tree-node__content {
    height: 33px;
    background-color: transparent;
  }

  .el-tree-node > .el-tree-node__content:hover {
    background-color: transparent;
  }

  .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
    background-color: transparent;
  }

  .custom-tree-node {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    display: inline-block;
  }

  .el-tree-node__label {
    margin-left: 9px;
  }

  .el-tree-node__content {
    position: relative;
  }

  .el-tree-node__content:hover .el-tree-node__label {
    overflow: visible;
    position: relative;
    z-index: 1;
  }
}
</style>
